s='(((2*x=38-(12*x+17)*3)))()'
def f(text):
    m=0
    for c in text:
        if c=='(':
            m+=1
        elif c==')':
            m-=1
        if m<0:
            return False
    return m==0
print(f(s))
def drac(text):
    while '()' in text or '{}' in text:
        text=text.replace('()','')
        text=text.replace('[]','')
        text=text.replace('{}','')
    return not text
print(drac('()((){}[]{})'))
